package com.gsafety.wellsfort.common.util;


public class JsonResult {

    private int code;// 是否成功
    private String msg;// 提示信息
    private Object data = null; // 其他信息

    @Override
    public String toString() {
        return "JsonResult{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    /**
     * 默认请求成功，返回一个obj
     *
     * @param data
     *            其他信息
     * @return
     */
    public static JsonResult success(Object data) {
        return new JsonResult(200, "ok",
                data);
    }

    public JsonResult() {
    }

    /**
     * 请求失败，返回一个msg
     *
     * @param msg
     *            自己定义的msg
     * @return
     */
    public static JsonResult fail(String msg) {
        return new JsonResult(-1, msg, "");
    }

    /**
     * 系统繁忙，返回一个msg
     *
     *
     *            自己定义的msg
     * @return
     */
    public static JsonResult busy() {
        return new JsonResult(-99, "系统繁忙", "");
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public JsonResult(int code) {
        this(code, null);
    }

    public JsonResult(int code, String msg) {
        this(code, msg, null, null, null);
    }

    public JsonResult(int code, String msg, Object data) {
        this(code, msg, null, data);
    }

    public JsonResult(int code, String msg, String sign, Object data) {
        this(code, msg, null, sign, data);
    }

    public JsonResult(int code, String msg, String token, String sign, Object data) {
        super();
        this.code=code;
        this.msg=msg;
        setData(data);
    }
}

